package com.william.lifetraxer.util;

import java.util.List;
import java.util.Iterator;

public class PointsComparerHelper {

	private static double twoPointsComparer( Point pointA , Point pointB )
	{
		double longitudeD_value = pointA.getLongitude() - pointB.getLongitude();
		double latitudeD_value = pointA.getLatitude() -pointB.getLatitude();
		
		return (longitudeD_value * longitudeD_value + latitudeD_value * latitudeD_value)/(180*180 + 360*360);
	}
	
	public static double getResult( List<Point> pointGroupA , List<Point> pointGroupB )
	{
		double result = 0.0;
		
		Iterator<Point> itA = pointGroupA.iterator();
		Iterator<Point> itB = pointGroupB.iterator();
		
		if(pointGroupA.size() == pointGroupB.size())
		{
			while(itA.hasNext())
			{
				result += twoPointsComparer((Point)itA.next(),(Point)itB.next());
			}
			
			return result/pointGroupA.size();
		}
		else if(pointGroupA.size() > pointGroupB.size())
		{
			while(itB.hasNext())
			{
				result += twoPointsComparer((Point)itA.next(),(Point)itB.next());
			}
			
			return result/pointGroupB.size();
		}
		else
		{
			while(itA.hasNext())
			{
				result += twoPointsComparer((Point)itA.next(),(Point)itB.next());
			}
			
			return result/pointGroupA.size();
		}
	}
	
//	public static void main(String[] args) {
//		List<Point> pointGroupA = new ArrayList<Point>(); 
//		pointGroupA.add(new Point(100.0001232 , 89.2313212));
//		pointGroupA.add(new Point(100.0002237 , 89.2314014));
//		pointGroupA.add(new Point(100.0002933 , 89.2315001));
//		pointGroupA.add(new Point(100.0003231 , 89.2315905));
//		pointGroupA.add(new Point(100.0003991 , 89.2316882));
//		pointGroupA.add(new Point(100.0004805 , 89.2317013));
//		pointGroupA.add(new Point(100.0005902 , 89.2318123));
//		pointGroupA.add(new Point(100.0006800 , 89.2319222));
//		pointGroupA.add(new Point(100.0007901 , 89.2320017));
//		
//		List<Point> pointGroupB = new ArrayList<Point>(); 
//		pointGroupB.add(new Point(100.0003112 , 89.2315321));
//		pointGroupB.add(new Point(100.0003221 , 89.2314623));
//		pointGroupB.add(new Point(100.0003221 , 89.2311253));
//		pointGroupB.add(new Point(100.0004121 , 89.2316234));
//		pointGroupB.add(new Point(100.0005313 , 89.2316321));
//		pointGroupB.add(new Point(100.0006432 , 89.2317532));
//		pointGroupB.add(new Point(100.0006234 , 89.2318731));
//		pointGroupB.add(new Point(100.0001632 , 89.2318452));
//		pointGroupB.add(new Point(100.0007012 , 89.2329567));
//		
//		System.out.println(PointsComparer.getResult(pointGroupA, pointGroupB));
//		
//	}

}
